﻿using System;
using System.Web.Mvc;
using BSU.CSCE.Web.Models;

namespace BSU.CSCE.Web.Controls.Pager
{
    public static class PaginationExtensions
    {
        public static Pager Pager(this HtmlHelper helper, string viewDataKey)
        {
            var dataSource = helper.ViewContext.ViewData.Eval(viewDataKey) as PagerViewModel;

            if (dataSource == null)
            {
                throw new InvalidOperationException(
                    string.Format("Item in ViewData with key '{0}' is not an PagerViewModel.",
                                  viewDataKey));
            }

            return helper.Pager(dataSource);
        }

        public static Pager Pager(this HtmlHelper helper, PagerViewModel model)
        {
            return new Pager(model, helper.ViewContext.HttpContext.Request);
        }

        public static Pager Pager(this HtmlHelper helper, PagerViewModel model,
                                  string paginationFirstText, string paginationPrevText, string paginationNextText,
                                  string paginationLastText)
        {
            return new Pager(model, helper.ViewContext.HttpContext.Request,
                             paginationFirstText, paginationPrevText, paginationNextText, paginationLastText);
        }
    }
}
